package db

import (
	"context"
	"github.com/redis/go-redis/v9"
	"github.com/sirupsen/logrus"
	"server/libs/log"
)

var redisDB *redis.Client

func InitRedis(redisAddr string, redisPwd string) {

	redisDB = redis.NewClient(&redis.Options{
		Addr:     redisAddr,
		Password: redisPwd,
		DB:       0,
	})
	//redis是否工作正常检测
	ctx := context.Background()
	err := redisDB.Ping(ctx).Err()
	if err != nil {
		log.Logrus().WithFields(logrus.Fields{}).Panic("redis链接错误")
		return
	}

}

func Redis() *redis.Client {
	return redisDB
}
